package main

func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
	n1 := l1
	n2 := l2
	n := &ListNode{}
	head := n
	for n1 != nil && n2 != nil {
		var node *ListNode
		if n1.Val < n2.Val {
			node = &ListNode{Val: n1.Val}
			n1 = n1.Next
		} else {
			node = &ListNode{Val: n2.Val}
			n2 = n2.Next
		}
		n.Next = node
		n = n.Next
	}
	if n1 != nil {
		n.Next = n1
	} else {
		n.Next = n2
	}
	return head.Next
}
